/** \file    bsgt.h
  * \brief   storable segmentation data, 'b' here stands for brief & binary.
  * \date    2002
  * \author  Fedor Chelnokov
  * \version $Header: /home/cscom1r4/cvsroot/cs/include/segm/bsgt.h,v 1.2 2005/04/04 04:10:16 cscom1r4 Exp $
  */

#ifndef _bsgt_h_
#define _bsgt_h_

#include "new_exception.h"
#include "imglib/imageclass.h"
#include "xtd/indexed_vector.h"
#include <biostream>

inline xtd::bostream & operator << (xtd::bostream &b, const byte_color &c)
	{ return b << reinterpret_cast<const xtd::int32u&>(c); }
inline xtd::bistream & operator >> (xtd::bistream &b, byte_color &c)
	{ return b >> reinterpret_cast<xtd::int32u&>(c); }

class bsgt {
public:
	//index - segment color
	byte_color		color;
	typedef byte_color index_type;
	index_type index() const
		{ return color; }

	//bp weights bitmap
	enum WeightsEffect {
		WeightsDepend	= 1,
		HalfCovered		= 2		///< segment is more than half covered by displaced mask or should be included in mask by other reasons
	};
	xtd::int32u		weightsEffect;
	xtd::float32	wIn, wOut;
	mutable bool	tOn;		///< segment is (in)active with previously specified thresholds
	void testAgainstThresholds(float tIn, float tOut) const;
};

inline xtd::bostream & operator << (xtd::bostream &b, const bsgt &g)
	{ return b << g.color << g.weightsEffect << g.wIn << g.wOut; }
inline xtd::bistream & operator >> (xtd::bistream &b, bsgt &g)
	{ return b >> g.color >> g.weightsEffect >> g.wIn >> g.wOut; }

EXCEPTION(bad_signature, "signature in bsgt file is not found")

class bsgtt: public xtd::indexed_vector<bsgt> {
public:
	typedef xtd::indexed_vector<bsgt> superclass;

	static void writeHeader(xtd::bostream &b, xtd::int32u scount);
};

xtd::bistream & operator >> (xtd::bistream &b, bsgtt &g);

#endif //_bsgt_h_
